import torch as t
from torch import nn
def l1_regularization(model, config):
    l1_value = 0.0
    for layer in model.modules():
        if isinstance(layer, nn.Conv2d):
            l1_value += t.sum(t.abs(layer.weight.data))
    l1_value = config.l1_regularization_rate * l1_value
    return l1_value


